package com.pcitc.app.model;

import com.pcitc.app.model.BaseObject;

import java.util.HashSet;
import java.util.Set;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;

import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;

import java.io.Serializable;

@Entity
@Table(name="TBL_USER",schema="ADMIN")
public class TblUser extends BaseObject implements Serializable {
    private Long userid;
    private TblOrg tblOrg;
    private String usercode;
    private String pwd;
    private String username;
    private String tel;
    private String mail;
    private String address;
    private String auditresult;
    private Set<TblUserRole> tblUserRoles = new HashSet<TblUserRole>(0);
    private Set<TblUserPosition> tblUserPositions = new HashSet<TblUserPosition>(0);
    
    public TblUser(){
    	
    }
    
    public TblUser(final String usercode){
    	this.usercode = usercode;
    }

    @Id  @GeneratedValue(strategy = GenerationType.AUTO)    
    public Long getUserid() {
        return this.userid;
    }
    
    public void setUserid(Long userid) {
        this.userid = userid;
    }
@ManyToOne(fetch=FetchType.LAZY)
    @JoinColumn(name="ORGID", nullable=false)
    public TblOrg getTblOrg() {
        return this.tblOrg;
    }
    
    public void setTblOrg(TblOrg tblOrg) {
        this.tblOrg = tblOrg;
    }
    
    @Column(name="USERCODE", length=256)
    public String getUsercode() {
        return this.usercode;
    }
    
    public void setUsercode(String usercode) {
        this.usercode = usercode;
    }
    
    @Column(name="PWD", length=256)
    public String getPwd() {
        return this.pwd;
    }
    
    public void setPwd(String pwd) {
        this.pwd = pwd;
    }
    
    @Column(name="USERNAME", length=256)
    public String getUsername() {
        return this.username;
    }
    
    public void setUsername(String username) {
        this.username = username;
    }
    
    @Column(name="TEL", length=256)
    public String getTel() {
        return this.tel;
    }
    
    public void setTel(String tel) {
        this.tel = tel;
    }
    
    @Column(name="MAIL", length=256)
    public String getMail() {
        return this.mail;
    }
    
    public void setMail(String mail) {
        this.mail = mail;
    }
    
    @Column(name="ADDRESS", length=256)
    public String getAddress() {
        return this.address;
    }
    
    public void setAddress(String address) {
        this.address = address;
    }
    
    @Column(name="AUDITRESULT", length=10)
    public String getAuditresult() {
        return this.auditresult;
    }
    
    public void setAuditresult(String auditresult) {
        this.auditresult = auditresult;
    }
@OneToMany(cascade=CascadeType.ALL, fetch=FetchType.LAZY, mappedBy="tblUser")
    public Set<TblUserRole> getTblUserRoles() {
        return this.tblUserRoles;
    }
    
    public void setTblUserRoles(Set<TblUserRole> tblUserRoles) {
        this.tblUserRoles = tblUserRoles;
    }
@OneToMany(cascade=CascadeType.ALL, fetch=FetchType.LAZY, mappedBy="tblUser")
    public Set<TblUserPosition> getTblUserPositions() {
        return this.tblUserPositions;
    }
    
    public void setTblUserPositions(Set<TblUserPosition> tblUserPositions) {
        this.tblUserPositions = tblUserPositions;
    }

    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        TblUser pojo = (TblUser) o;

        if (tblOrg != null ? !tblOrg.equals(pojo.tblOrg) : pojo.tblOrg != null) return false;
        if (usercode != null ? !usercode.equals(pojo.usercode) : pojo.usercode != null) return false;
        if (pwd != null ? !pwd.equals(pojo.pwd) : pojo.pwd != null) return false;
        if (username != null ? !username.equals(pojo.username) : pojo.username != null) return false;
        if (tel != null ? !tel.equals(pojo.tel) : pojo.tel != null) return false;
        if (mail != null ? !mail.equals(pojo.mail) : pojo.mail != null) return false;
        if (address != null ? !address.equals(pojo.address) : pojo.address != null) return false;
        if (auditresult != null ? !auditresult.equals(pojo.auditresult) : pojo.auditresult != null) return false;

        return true;
    }

    public int hashCode() {
        int result = 0;
        result = (tblOrg != null ? tblOrg.hashCode() : 0);
        result = 31 * result + (usercode != null ? usercode.hashCode() : 0);
        result = 31 * result + (pwd != null ? pwd.hashCode() : 0);
        result = 31 * result + (username != null ? username.hashCode() : 0);
        result = 31 * result + (tel != null ? tel.hashCode() : 0);
        result = 31 * result + (mail != null ? mail.hashCode() : 0);
        result = 31 * result + (address != null ? address.hashCode() : 0);
        result = 31 * result + (auditresult != null ? auditresult.hashCode() : 0);

        return result;
    }

    public String toString() {
        StringBuffer sb = new StringBuffer(getClass().getSimpleName());

        sb.append(" [");
        sb.append("userid").append("='").append(getUserid()).append("', ");
        sb.append("tblOrg").append("='").append(getTblOrg()).append("', ");
        sb.append("usercode").append("='").append(getUsercode()).append("', ");
        sb.append("pwd").append("='").append(getPwd()).append("', ");
        sb.append("username").append("='").append(getUsername()).append("', ");
        sb.append("tel").append("='").append(getTel()).append("', ");
        sb.append("mail").append("='").append(getMail()).append("', ");
        sb.append("address").append("='").append(getAddress()).append("', ");
        sb.append("auditresult").append("='").append(getAuditresult()).append("', ");
        
        
        sb.append("]");
      
        return sb.toString();
    }

}
